<template>
  <div>
    <el-form
      status-icon
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="旧密码" prop="oldpass">
        <el-input
          type="password"
          v-model="oldpass"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="newPass">
        <el-input
          type="password"
          v-model="newPass"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="checkPass">
        <el-input
          type="password"
          v-model="checkPass"
          autocomplete="off"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="funsure">确认</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { hangepass, editpwd } from "../../apis/user";
export default {
  data() {
    return {
      oldpass: "",
      checkPass: "",
      newPass: "",
      id: "",
    };
  },
  methods: {
    //点击确认 查看旧密码
    funsure() {
      let id = localStorage.getItem("id");
      // console.log(id , this.oldpass);
      hangepass({ oldPwd: this.oldpass, id }).then((res) => {
       if(res.data.code==0){
         //修改密码
         editpwd({ newPwd: this.newPass, id }).then((res) => {
           if (res.data.code == 0) {
             console.log(res.data.code);
             this.$message({
               message: "恭喜你,修改密码成功",
               type: "success",
             });
             this.$router.push("/");
           }
         });
       }else{
         alert('旧密码不对')
       }

      })
        
      //修改密码
    },

    //重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="less">
.el-main[data-v-fae5bece] {
  background-color: #e9eef3;
  color: #333;
  text-align: left;
  line-height: 50px;
}

.el-input__inner {
  width: 210px;
}
</style>